package com.example.fanplant;

import com.example.fanplant.controller.FansController;
import com.example.fanplant.controller.TestController;
import com.example.fanplant.model.User;
import org.springframework.lang.NonNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class LearnJava {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("apple");
        list.add("banana");
        list.add("orange");
        list.add("pear");

        for (String fruit : list) {
            System.err.println(fruit);
        }

        System.err.println("hello World!!====>>ZHDL");

//        User person = new User();
        Class classs = User.class;//one
//        Class<? extends User> personClazz01 = person.getClass();//two
        try {
            User object = (User) classs.newInstance();

            Method[] lists= classs.getDeclaredMethods();

            for (int i = 0; i < lists.length; i++) {
                System.out.println("list:"+i+"     "+lists[i].getName()+"");
            }

            Method m1 = classs.getDeclaredMethod("setTestStr", String.class);
            m1.setAccessible(true);
            m1.invoke(object, "test private str");
            Method m2 = classs.getDeclaredMethod("getAge");
            m2.setAccessible(true);
             System.out.println("新数据:"+m2.invoke(object)+"    获取方法的返回类型"+m2.getReturnType());
            Method m3 = classs.getDeclaredMethod("toString");
            m3.setAccessible(true);
            System.out.println("新数据:" + m3.invoke(object) + "");
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

    }
}
